# -*- coding:utf-8 -*-
# @FileName  :pg_connect.py
# @Time      :2024/2/4 15:20
import psycopg2

URI = "dbname=somedata user=somedata password=somedata host=127.0.0.1 port=5432"


def get_connect():
    conn = psycopg2.connect(URI)

    cur = conn.cursor()
    return conn, cur


def create_table_test():
    conn, cur = get_connect()
    cur.execute("CREATE TABLE test1 (id serial PRIMARY KEY, num integer, data varchar);")
    print("ok")


def query():
    conn, cur = get_connect()
    cur.execute("SELECT * FROM test1;")
    resp = cur.fetchone()
    print(resp)


if __name__ == '__main__':
    # create_table_test()
    query()